export function useVerify() {
	function verifyMobile(mobile) {  // 检验手机号
		let str = mobile.toString()
		return new Promise((resolve, reject) => {
			if (str.length <= 0) reject('请输入账号~')
			else if (!/^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/.test(str)) reject('请输入正规的账号~')
			else resolve()
		})
	}
	
	function verifyFun(values, texts, length = 6) {
		let str = values[0].toString()
		return new Promise((resolve, reject) => {
			if (str.length <= 0) reject(texts[0])
			else if (str.length < length) reject(texts[1])
			else if (values[1] && values[0] != values[1]) reject(texts[2])
			else resolve()
		})
	}
	
	// 校验手机验证码
	let verifyCode = async code => await verifyFun([code], ['请输入手机验证码~', '请输入正确的手机验证码~'])
	
	async function verifyOldMobile(mobile) {  // 验证旧手机号
		let { user } = uni.$store()
		return await verifyFun([mobile, user.userInfo?.mobile], ['请输入旧手机号~', '请输入合法的手机号~', '请输入正确的旧手机号~'], 11)
	}
	
	// 校验账号密码
	let verifyPassword = async password => await verifyFun([password], ['请输入账号密码~', '账号密码应不低于 6位~'])
	
	// 校验新密码
	let verifyNewPassword = async password => await verifyFun([password], ['请输入新密码~', '新密码应不低于 6位~'])
	
	// 校验旧密码
	let verifyOldPassword = async password => await verifyFun([password], ['请输入旧密码~', '旧密码应不低于 6位~'])
	
	async function verifyTwicePassword(newPassword, oldPassword) {  // 校验新密码
		return await verifyFun([newPassword, oldPassword], ['请输入确认密码~', '确认密码应不低于 6位~', '两次密码不一致~'])
	}
	
	return { verifyMobile, verifyCode, verifyPassword, verifyNewPassword, verifyTwicePassword, verifyOldMobile, verifyOldPassword }
}